<?php

namespace app\api\controller\auth;

use app\api\controller\AuthBase;
use think\facade\Db;
class Group extends AuthBase
{
    public static $name = 'controller.auth.Group';
    /**
     * 当前权限组列表
     * @return void
     */
    public function list()
    {
        try{
            $result = [
                'list'=>[],
                'group'=>[$this->groupId],
                'remark'=>'',
            ];
            $all = Db::name('admin_group')->select();
            foreach ($all as $datum) {
                if ($datum['rules']) {
                    if ($datum['rules'] == '*') {
                        $datum['rules']  = '所有项';
                    }else{
                        $rules = explode(',', $datum['rules']);
                        if ($rules) {
                            $datum['rules']  = count($rules).' 项';
                        }
                    }
                }else{
                    $datum['rules']  = '没有分配权限';
                }
                array_push($result['list'],$datum);
            }
            return returnResult(config("config.code.success"),config("config.describe.success"),$result);
        }catch (\Exception $e){
            exception($e,self::$name.'.index');
        }
    }
}